<template>
	<view class="container">
		<z-paging ref="paging" v-model="assetsData" :auto-clean-list-when-reload="false"
			:auto-scroll-to-top-when-reload="false" @query="queryList">
			<!-- 视图 -->
			<view class="charts-box">
				<qiun-data-charts type="gauge" :opts="opts" :chartData="chartData" />
			</view>
			<!-- 标题内容区 -->
			<view class="info_card">
				<BsinTitle text="钱包地址"></BsinTitle>
				<view class="info_detail">
					<view class="wallent_location">
						<span class="info">{{anyWebInfo.walletAddress}}</span>
						<span class="icon" @click="copyContract">
							<image style="width: 20px;height: 20px;" src="../static/images/my/copy.png"></image>
						</span>
					</view>
				</view>
			</view>
			<view class="line_view">
				<view style="z-index: 100;position: sticky;top :0; background: #fff;">
					<z-tabs @change="changeTab" :list="tabsList" active-color='var(--echo-main-color)'></z-tabs>
				</view>
				<!-- nft展示 -->
				<view class="nft_lists_card" v-show="tabShowType == 0">
					<BsinNftCard nftNameColor="#333" background="rgb(241, 241, 241)" v-for="(item, index) in assetsData"
						:key="index" :item="item" imgStyle="width: 165px; height:170px;margin-top: 10px;" @toDetail="toDetail(item.serialNo)">
					</BsinNftCard>
				</view>
				<view class="force_trading" v-show="tabShowType == 1">
					<trading-card v-for="(item, index) in assetsData" :item="item" :key="index"></trading-card>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import {
		getMyDigitalAssets,
		getMyAccountSerialList
	} from '@/config/customer.js'
	export default {
		data() {
			return {
				// 顶部tabs
				tabShowType: 0,
				tabsList: [{
					name: '徽章',
				}, {
					name: '数字积分',
				}],
				s11eDaoToken: '',
				// nft积分 资产信息列表
				assetsData: [],
				// ucharts
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['gauge'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ["#fe7c24", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: undefined,
					title: {
						name: "0",
						fontSize: 25,
						color: "#fe7c24",
						offsetY: 0
					},
					subtitle: {
						name: "原力",
						fontSize: 15,
						color: "#fe7c24",
						offsetY: 0
					},
					extra: {
						gauge: {
							type: "progress",
							width: 20,
							labelColor: "#666666",
							startAngle: 0.75,
							endAngle: 0.25,
							startNumber: 0,
							endNumber: 100,
							labelFormat: "",
							splitLine: {
								fixRadius: -10,
								splitNumber: 10,
								width: 15,
								color: "#FFFFFF",
								childNumber: 5,
								childWidth: 12
							},
							pointer: {
								width: 24,
								color: "auto"
							}
						}
					}
				},
				// 钱包信息
				anyWebInfo: {
					walletAddress: ''
				},
				// 用户信息
				customerInfo: '',
				// 账户信息
				accountInfo: []
			}
		},

		created() {
			// 客户编号
			this.customerInfo = uni.getStorageSync('customerInfo');
			// 钱包地址
			if (!this.util.isEmpty(uni.getStorageSync('ANYWEBINFO'))) {
				this.anyWebInfo.walletAddress = uni.getStorageSync('ANYWEBINFO').address[0];
			}
		},
		onReady() {
			this.getServerData();
		},
		async onShow() {
			let res = await getMyDigitalAssets({
				customerNo: this.customerInfo.customerNo
			})
			console.log(res)
			this.accountInfo = res.data.accountInfo
			this.opts.title.name = res.data.accountInfo[0].balance + ""
		},
		methods: {
			// nft详情
			toDetail(serialNo) {
				uni.navigateTo({
					url: "/pagesDao/NftDetail?serialNo=" + serialNo
				})
			},
			// 顶部模块的改变
			changeTab(index) {
				console.log(index)
				this.tabShowType = index
				this.$refs.paging.reload()
			},

			queryList(pageNo, pageSize) {
				// 调用查询nft接口
				if (this.tabShowType == 0) {
					this.getCustomerWalletInfo(0)
				}
				if (this.tabShowType == 1) {
					this.$refs.paging.complete([])
					this.getCustomerWalletInfo(1)
				}
			},

			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: [{
							"value": 0.2,
							"color": "#fff"
						}, {
							"value": 0.8,
							"color": "#2fc25b"
						}, {
							"value": 1,
							"color": "#f04864"
						}],
						series: [{
							name: "完成率",
							data: 0.66
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},

			copyContract() {
				uni.setClipboardData({
					data: this.anyWebInfo.walletAddress,
					success: function() {
						console.log('success');
					},
				});
			},

			/**
			 * 接口对接
			 */
			// 1.nft资产接口
			async getCustomerWalletInfo(tabType) {
				if (tabType == 0) {
					let res = await getMyDigitalAssets({
						customerNo: this.customerInfo.customerNo
					})
					this.$refs.paging.complete(res.data.nftInfo)
				} else if (tabType == 1) {
					let res = await getMyAccountSerialList({
						customerNo: this.customerInfo.customerNo
					})
					console.log(res.data[0].yuanli)
					this.$refs.paging.complete(res.data[0].yuanli)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.charts_box {
		width: 100%;
		height: 280px;
		padding-top: 80rpx;
	}

	.nft_lists_card {
		display: flex;
		justify-content: space-around;
		flex-wrap: wrap;
		padding: 30rpx;
	}

	.info_card {

		.info_detail {
			background-color: #fff;
			padding: 2rpx 30rpx 30rpx 30rpx;
			font-size: 28rpx;
			margin-bottom: 20rpx;
			border-bottom: 1px solid #ede6e6;

			.wallent_location {
				margin-top: 12rpx;

				.info {
					width: 90%;
					/*1.强制不换行*/
					white-space: nowrap;
					/*2.溢出隐藏*/
					overflow: hidden;
					/*3.超出部分用省略号表示*/
					text-overflow: ellipsis;
				}

				span {
					display: inline-block;
				}
			}
		}
	}

	::v-deep .u-tabs__wrapper__nav__line {
		display: none;
	}
</style>
